<template>
  <view class="privacy-container">
    <uni-list>
      <!-- 个人信息 -->
      <uni-list-item>
        <template #header>
          <text class="section-title">个人信息</text>
        </template>
      </uni-list-item>
      
      <uni-list-item 
        title="个人资料可见性"
        :showSwitch="true"
        :switchChecked="settings.profileVisible"
        @switchChange="toggleSetting('profileVisible')"
      />
      
      <uni-list-item 
        title="允许他人查看我的收藏"
        :showSwitch="true"
        :switchChecked="settings.favoritesVisible"
        @switchChange="toggleSetting('favoritesVisible')"
      />

      <!-- 互动设置 -->
      <uni-list-item>
        <template #header>
          <text class="section-title">互动设置</text>
        </template>
      </uni-list-item>
      
      <uni-list-item 
        title="允许他人评论"
        :showSwitch="true"
        :switchChecked="settings.allowComments"
        @switchChange="toggleSetting('allowComments')"
      />
      
      <uni-list-item 
        title="允许私信"
        :showSwitch="true"
        :switchChecked="settings.allowMessages"
        @switchChange="toggleSetting('allowMessages')"
      />

      <!-- 位置信息 -->
      <uni-list-item>
        <template #header>
          <text class="section-title">位置信息</text>
        </template>
      </uni-list-item>
      
      <uni-list-item 
        title="允许使用位置信息"
        :showSwitch="true"
        :switchChecked="settings.locationEnabled"
        @switchChange="toggleSetting('locationEnabled')"
      />
    </uni-list>
  </view>
</template>

<script setup>
import { ref } from 'vue';

const settings = ref({
  profileVisible: true,
  favoritesVisible: true,
  allowComments: true,
  allowMessages: true,
  locationEnabled: false
});

const toggleSetting = (key) => {
  settings.value[key] = !settings.value[key];
  saveSettings();
};

const saveSettings = async () => {
  try {
    await uni.showLoading({ title: '保存中...' });
    // 实现保存设置逻辑
    await new Promise(resolve => setTimeout(resolve, 500));
    
    uni.showToast({
      title: '保存成功',
      icon: 'success'
    });
  } catch (error) {
    uni.showToast({
      title: '保存失败',
      icon: 'error'
    });
  } finally {
    uni.hideLoading();
  }
};
</script>

<style lang="scss" scoped>
.privacy-container {
  min-height: 100vh;
  background: #f8f8f8;
  padding: 20rpx 0;
}

.section-title {
  font-size: 28rpx;
  color: #999;
  padding: 20rpx 30rpx;
  display: block;
}
</style> 